package tree;

import java.util.ArrayList;

import resources.State;
import dataType.Man;
import dataType.Person;
import dataType.Woman;

public class Node {
	private Tree myTree;
	private Object data; //Object attribute guarantee use of any type of data
	//For example, we can manage a tree of person, dogs, ships
	private ArrayList<Node> childNodes = new ArrayList<Node>();
	
	public Node() { //needed for antony's woman case
		super();
		this.data = null;
		this.myTree = null;
	}
		
	public Node(String name) {
		super();
		Person person = new Person(name);
		this.data = person;
		person.setState(State.live);
	}
	
	public Node(String name, State state) {
		super();
		Woman woman = new Woman(name);
		woman.setState(state);
		this.data = woman;
	}
	
	public Node(String name, State state, Node someWoman) {
		super();
		Man man = new Man(name);	//needed by the "single woman" case
		man.setState(state);
		man.setMarriedWith(someWoman);
		if(someWoman.getChildNodes().isEmpty()!=true)
			childNodes.addAll(someWoman.getChildNodes());
		this.data = man;
	}
	
	public Node(Node someWoman) {
		super();
		Man man = new Man();
		man.setMarriedWith(someWoman);
		this.data = man;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public ArrayList<Node> getChildNodes() {
		return childNodes;
	}

	public void setChildNodes(ArrayList<Node> childNodes) {
		this.childNodes = childNodes;
	}
	
	public void addChild(Node child){
		//ok, insert the child
		childNodes.add(child);
		//almost forget.. if this are a couple, she needs to know their suns too?
		//Person person = (Person) data;
		//if(person!=null)
		//	System.out.println(person.getClass().getCanonicalName());
	
	}
	
	public void setName(String name){
		Person person = (Person) data;
		person.setName(name);
	}
	
	public boolean compareNodeToString(String name){
		//this is a man, not a person.. 
		Person person = (Person) data;
		if(person.getName().equals(name))
			return true;
		return false;
	}
	
	public boolean compareWoman(String name){
		Man man = (Man) data;
		Woman woman = (Woman) man.getMarriedWith().getData();
		if(woman.getName().equals(name))
			return true;
		return false;
	}
	
	public boolean compareManChild(String name){
		//search on this.arrayList
		return true;
	}
	
	public boolean compareWomanChild(String name){
		Man man = (Man) data;
		ArrayList childList = man.getMarriedWith().getChildNodes();
		//run over arrayList and compare. 
		return true;
	}
	
	public ArrayList<Node> coupleChildList(){
		Man man = (Man) data;
		ArrayList<Node> childList = childNodes;
		childList.addAll(man.getMarriedWith().getChildNodes());
		return childList;
	}
	
}
